package cc.javaee.bbs.dao;

import cc.javaee.bbs.model.Huifu;
import cc.javaee.bbs.model.PageBean;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class HuifuDao extends BaseDao {
    String ns = "";

    public List<Map<String, Object>> findpage(PageBean<Map<String, Object>> page) {
        return this.getSqlSession().selectList(ns + "findpageHuifu", page);
    }

    public int findpagecount(PageBean<Map<String, Object>> page) {
        return this.getSqlSession().selectOne(ns + "findpagecountHuifu", page);
    }

    public List<Huifu> find(Huifu Huifu) {
        return this.getSqlSession().selectList(ns + "findHuifu", Huifu);
    }

    public List<Huifu> findByIds(Integer tieziid, Integer type, List ids) {
        Map map = new HashMap();
        map.put("tieziid", tieziid);
        map.put("type", type);
        map.put("ids", ids);
        return this.getSqlSession().selectList(ns + "findByIds", map);
    }

    public List<Huifu> findByTieziid(Integer tieziid, Integer createuserid) {
        Map map = new HashMap();
        map.put("tieziid", tieziid);
        map.put("createuserid", createuserid);
        return this.getSqlSession().selectList(ns + "findByTieziid", map);
    }

    public List<Huifu> select(Huifu Huifu) {
        return this.getSqlSession().selectList(ns + "select", Huifu);
    }

    public void insert(Huifu Huifu) {
        this.getSqlSession().insert(ns + "insertHuifu", Huifu);
    }

    public void deletebytiezi(Integer id) {
        this.getSqlSession().delete(ns + "deletebytiezi", id);
    }

    public void deletebycreateuserid(Integer createuserid) {
        this.getSqlSession().delete(ns + "deletebycreateuserid", createuserid);
    }

    public void update(Huifu Huifu) {
        this.getSqlSession().update(ns + "update", Huifu);
    }

    public Integer maxobderby(int id) {
        return this.getSqlSession().selectOne(ns + "maxobderby", id);
    }

    public void updatedelete(int id) {
        Huifu huifu = new Huifu();
        huifu.setId(id);
        huifu.setIsdel("1");
        this.getSqlSession().update(ns + "update", huifu);
    }

    /**
     * 根据帖子id和类型和参与的人查询回复
     *
     * @param tieziId
     * @param type
     * @param listCode
     * @return
     */
    public List<Huifu> getHuiFuByTieziidType(Integer tieziId, int type, Integer createuserid, Integer myCustId) {
        Map map = new HashMap();
        map.put("tieziId", tieziId);
        map.put("type", type);
        map.put("createuserid", createuserid);
        map.put("myCustId", myCustId);
        return this.getSqlSession().selectList(ns + "getHuiFuByTieziidType", map);
    }

}